<?php

namespace App\Jobs;

use App\Exceptions\ApiException;
use App\Libraries\msg\Push;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class SendPush implements ShouldQueue
{
	use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
	
	protected $uid;
	protected $title;
	protected $content;
	protected $extra;
	
	/**
	 * Create a new job instance.
	 *
	 * @return void
	 */
	public function __construct($uid,$title,$content,$extra)
	{
		//
		$this->uid = $uid;
		$this->title = $title;
		$this->content = $content;
		$this->extra = $extra;
	}
	
	/**
	 * Execute the job.
	 *
	 * @return void
	 */
	public function handle()
	{
		//
		$msg = new Push();
		$return = $msg->send($this->uid,$this->title,$this->content,$this->extra);
		if(empty($return)){
			throw new ApiException('发送推送失败');
		}
	}
	
	
	/**
	 * Handle a job failure.
	 *
	 * @return void
	 */
	public function failed()
	{
		// Called when the job is failing...
	}
}
